package com.dalei.vdsmanager.detection.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.dalei.vdsmanager.detection.model.VehicleInformation;

public class VehicleInformationDaoImpl extends HibernateDaoSupport implements
		VehicleInformationDao {

	@Override
	public void saveVehicleInformation(VehicleInformation vehicleInformation) {
		// TODO Auto-generated method stub
		getHibernateTemplate().save(vehicleInformation);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<VehicleInformation> findVehicleInformations() {
		// TODO Auto-generated method stub
		String hql = "FROM VehicleInformationDao";
		List<VehicleInformation> vehicleInformations = getHibernateTemplate()
				.find(hql);
		return vehicleInformations;
	}

	@Override
	public VehicleInformation findVehicleInformationById(int id) {
		// TODO Auto-generated method stub
		Criteria criteria = getSession().createCriteria(
				VehicleInformation.class);
		criteria.add(Restrictions.eq("id", id));
		VehicleInformation vehicleInformation = (VehicleInformation) criteria
				.uniqueResult();
		return vehicleInformation;
	}

	@Override
	public void updateVehicleInformation(VehicleInformation vehicleInformation) {
		// TODO Auto-generated method stub
		getHibernateTemplate().update(vehicleInformation);
	}

	@Override
	public void deleteVehicleInformation(VehicleInformation vehicleInformation) {
		// TODO Auto-generated method stub
		getHibernateTemplate().delete(vehicleInformation);
	}

}
